package priv.lirenhe.dissertation.cacher;

import org.apache.log4j.Logger;

public class CacheListener{
	  Logger logger = Logger.getLogger("cacheLog");
	  private CacherManager cacheManager;
	  public CacheListener(CacherManager cacheManager) {
	    this.cacheManager = cacheManager;
	  }

	  public void startListen() {
	    new Thread(){
	      public void run() {
	        while (true) {
	          for(String key : cacheManager.getAllKeys()) {
	            if (cacheManager.isTimeOut(key)) {
	             cacheManager.clearByKey(key);
	             logger.info(key + "缓存被清除");
	           }
	          } 
	        }
	      } 
	    }.start();
	  }
	}